package grafoS;

/**
 * Gcol is a program to help users to learn a little about graph coloring, in
 * this software, you can learn some coloring algorithms, and add your own
 * algorithm for coloring.You can also learn BFS and DFS search. This tool, also
 * support the .col format from DIMACS (Center for Discrete Mathematics and
 * Theoretical Computer Science), so you can import a big graph and use all the
 * algorithms. Copyright (C) <2015> Clóvis Daniel Souza Silva, Samuel Silva de
 * Souza, Professor Leonardo Sampaio Rocha.
 * 
* This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
* This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
* You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 * contact: projetoGrafos@gmail.com
 */
/**
 * @author Daniel
 * @author Samuel
 */
public class Tranformador {

    /**
     * This method converts a obejct Graph to a GraphList
     *
     * @param g object Graph to be converted
     * @return a object GraphList equivalent to object Graph.
     */
    public GraphList transformaAdj(Graph g) {
        GraphList grafo = new GraphList(g.n);
        for (int i = 0; i < g.n; i++) {
            grafo.getA()[i] = new Adjacencia(grafo.getV()[i]);
            Adjacencia p = grafo.getA()[i];
            for (int j = 0; j < g.n; j++) {
                if (g.getGrafo()[i][j] == 1) {
                    p.setProx(new Adjacencia(grafo.getV()[j]));
                    p = p.getProx();

                }

            }
            p.setProx(null);
        }

        return grafo;
    }

    /**
     * This method converts a obejct GraphList to a Graph
     *
     * @param g object GraphList to be converted
     * @return a object Graph equivalent to object GraphList.
     */
    public Graph tranformaMat(GraphList g) {
        Graph grafo = new Graph(g.getN());

        for (int i = 0; i < g.getN(); i++) {
            if (g.getA()[i] != null) {
                Adjacencia p = g.getA()[i].getProx();
                while (p != null) {
                    grafo.getGrafo()[i][p.getDado().getNome()] = 1;
                    p = p.getProx();

                }
            }
        }

        return grafo;
    }
}
